package com.vimi8.ebb.service;

import com.vimi8.ebb.dto.TrainMemberDto;
import com.vimi8.ebb.model.ProductInfo;
import com.vimi8.ebb.model.TrainInfo;
import com.vimi8.ebb.model.TrainMember;
import com.vimi8.ebb.sqlprovider.ElectricityBusinessSqlProvider;
import com.vimi8.ebb.sqlprovider.TrainInfoSqlProvider;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by think on 2016/9/8.
 * 枚举分类表service
 */
@Mapper
public interface TrainMemberService {

    /**
     * @return
     */
@Insert("insert into train_members(id,train_id,member_name,member_type,member_image,member_sex,member_phone,enter_orientation,train_evaluate,member_address)" +
        " values(#{id},#{trainId},#{memberName},#{memberType},#{memberImage},#{memberSex},#{memberPhone},#{enterOrientation},#{trainEvaluate},#{memberAddress})")
    public int insertTrainMember(TrainMember trainMember);
    @InsertProvider(type = TrainInfoSqlProvider.class, method = "getInsertTrainMemberSql")
    public int batchTrainMember(@Param("trainMemberList")  List<TrainMember> trainMemberList);

    @Select("select id,train_address as trainAddress,train_address_code as trainAddressCode,train_teacher as trainTeacher,sex as sex,phone as phone,train_object as trainObject,train_date as trainDate,train_title as trainTitle,train_content as trainContent ,train_type as trainType,train_evaluate as trainEvaluate ,train_peoples as trainPeoples from train_info where 1=1 " +
            "and train_id=#{trainId}")
    public List<TrainMember> queryTrainMemberList(@Param("trainId")String trainId);

    @Select("<script>select count(ti.id) from train_info ti,train_members tm where ti.id=tm.train_id and 1=1 " +
            "<if test=\"memberName!=null and memberName!=''\"> and tm.member_name like CONCAT('%',#{memberName},'%')</if> " +
            "<if test=\"trainTitle!=null and trainTitle!=''\"> and train_title like CONCAT('%',#{trainTitle},'%')</if> " +
            "<if test=\"trainDate!=null and trainDate!=''\"> and train_date like CONCAT('%',#{trainDate},'%')</if> " +
            "<if test=\"addressCode!=null and addressCode!=''\"> and train_address_code like CONCAT('%',#{addressCode},'%')</if> " +
            "</script>")
    public int queryTrainMemeberCount(@Param("memberName")String memberName,@Param("trainTitle")String trainTitle,@Param("trainDate")String trainDate,@Param("addressCode")String addressCode);


    @Select("<script>select ti.id as trainId ,ti.train_title as trainTitle,ti.train_content as trainContent,member_name as memberName,member_type as memberType,member_sex as memberSex," +
            "member_phone AS memberPhone,enter_orientation as enterOrientation,tm.id as id,tm.train_evaluate as trainEvaluate,member_address as memberAddress,member_image as memberImage from " +
            "  train_info ti,train_members tm where ti.id=tm.train_id and 1=1 " +
            "<if test=\"memberName!=null and memberName!=''\"> and tm.member_name like CONCAT('%',#{memberName},'%')</if> " +
            "<if test=\"trainTitle!=null and trainTitle!=''\"> and ti.train_title like CONCAT('%',#{trainTitle},'%')</if> " +
            "<if test=\"trainDate!=null and trainDate!=''\"> and ti.train_date like CONCAT('%',#{trainDate},'%')</if> " +
            "<if test=\"addressCode!=null and addressCode!=''\"> and ti.train_address_code like CONCAT('%',#{addressCode},'%')</if> " +
            "  order by train_date desc limit #{index},#{size} </script>")
    public List<TrainMemberDto> queryTraMemberList(@Param("memberName")String memberName,@Param("trainTitle")String trainTitle, @Param("trainDate")String trainDate, @Param("addressCode")String addressCode, @Param("index")int index, @Param("size") int size);

    @Select("<script>select ti.id as trainId ,ti.train_title as trainTitle,ti.train_content as trainContent,member_name as memberName,member_type as memberType,member_sex as memberSex," +
            "member_phone AS memberPhone,enter_orientation as enterOrientation,tm.id as id,tm.train_evaluate as trainEvaluate,member_address as memberAddress from " +
            "  train_info ti,train_members tm where ti.id=tm.train_id and 1=1 " +
            "<if test=\"trainTitle!=null and trainTitle!=''\"> and ti.train_title like CONCAT('%',#{trainTitle},'%')</if> " +
            "<if test=\"trainDate!=null and trainDate!=''\"> and ti.train_date like CONCAT('%',#{trainDate},'%')</if> " +
            "<if test=\"addressCode!=null and addressCode!=''\"> and ti.train_address_code like CONCAT('%',#{addressCode},'%')</if> " +
            "  order by train_date desc</script>")
    public List<TrainMemberDto> queryTraMemberListForExcel(@Param("trainTitle")String trainTitle, @Param("trainDate")String trainDate, @Param("addressCode")String addressCode);

    /**
     * 根据培训学员信息ids批量删除培训信息
     * @param ids
     * @return
     */
    @Delete(" delete from train_members where id in (${ids})")
    public Integer deleteTraMenberBySelectedIds(@Param("ids")String ids);
}



